<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:forEach items="${adminPosts}" var="post">
    <tr>
        <!-- 序号 -->
        <td width="50px">
            <div style="width:50px;word-wrap:break-word;">${post.postId}</div>
        </td>
        <!-- 标题 -->
        <td width="300px">
            <div style="width:300px;word-wrap:break-word;">
                <a href="/postContent?postId=${post.postId}">${post.postTitle}</a>
            </div>
        </td>
        <!-- 发布者 -->
        <td>${post.user.userName}</td>
        <!-- 创建时间 -->
        <td>${post.postCreateTime}</td>

        <!-- 操作 -->
        <td>
            <input class="delete" type="button" value="删除">
        </td>
    </tr>
</c:forEach>
<script>
    $('.delete').click(function () {
        const msg = "您真的确定要删除吗？\n\n删除后不能复原！";
        if (confirm(msg) == true) {
            $.ajax({
                url: '/postDelete',
                method: 'get',
                data: {
                    postId: $(this).parent().parent().find('td').find('div').html(),
                },
                success: function (data) {
                    alert(data)
                    if (data == "删除帖子成功") {
                        getPosts();
                    }
                },
                error: function () {
                    alert("请求出错")
                }
            })
        }
        console.log($(this).parent().parent().find('td').find('div').html())
    });
</script>
